package com.zucc.controller;

import com.zucc.controller.req.*;
import com.zucc.controller.resp.InventoryResp;
import com.zucc.service.InventoryService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : charspan
 * @Description :
 * @create : 2021-12-24 1:52 下午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/inventories")
@Api(tags = "盘点计划管理")
public class InventoryController {
    @Resource
    private InventoryService inventoryService;

    @ApiOperation(value = "新增盘点计划")
    @PostMapping
    void add(@RequestBody @Validated InventoryAddReq req) {
        inventoryService.add(req);
    }

    @ApiOperation(value = "处理盘点计划")
    @PutMapping
    void modify(@RequestBody @Validated InventoryModifyReq req) {
        inventoryService.modify(req);
    }

    @ApiOperation(value = "删除盘点计划")
    @ApiImplicitParam(paramType = "path", name = "id", value = "盘点计划编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    void deleteOne(@PathVariable Long id) {
        inventoryService.deleteOne(id);
    }

    @ApiOperation(value = "盘点计划详情")
    @ApiImplicitParam(paramType = "path", name = "id", value = "盘点计划编号", dataType = "Long", example = "1", required = true)
    @GetMapping("/{id}")
    InventoryResp detail(@PathVariable Long id) {
        return inventoryService.detail(id);
    }

    @ApiOperation(value = "提交单项盘点结果")
    @PostMapping("/result/single")
    void submitSingleInventoryResult(@RequestBody @Validated InventoryResultDetailReq req) {
        inventoryService.submitSingleInventoryResult(req);
    }

    @ApiOperation(value = "批量提交盘点结果")
    @PostMapping("/result/batch")
    void submitBatchInventoryResult(@RequestBody @Validated InventoryResultReq req) {
        inventoryService.submitInventoryResult(req);
    }

    @ApiOperation(value = "盘点计划分页")
    @PostMapping("/page")
    PageData<InventoryResp> page(@RequestBody @Validated InventorySearchReq req) {
        return inventoryService.page(req);
    }

}
